package cinema.v1_0;

import cinema.v1_0.model.*;
import cinema.v1_0.service.CinemaService;
import cinema.v1_0.util.ConsoleUtil;

public class MainV1_0 {
    private static final CinemaService service = new CinemaService();

    public static void main(String[] args) {
        while (true) {
            System.out.println("\n========== 万东电影院 1.0 ==========");
            System.out.println("1 登录");
            System.out.println("2 查看用户");
            System.out.println("3 查看影片");
            System.out.println("4 查看影厅");
            System.out.println("5 查看场次");
            System.out.println("0 退出");
            int opt = ConsoleUtil.readInt("请选择: ");

            switch (opt) {
                case 1 -> login();
                case 2 -> listUsers();
                case 3 -> listMovies();
                case 4 -> listHalls();
                case 5 -> listSessions();
                case 0 -> {
                    System.out.println("感谢使用！");
                    return;
                }
                default -> System.out.println("输入错误！");
            }
        }
    }

    private static void login() {
        String name = ConsoleUtil.readLine("用户名: ");
        String pwd  = ConsoleUtil.readLine("密码: ");
        boolean ok = service.login(name, pwd);
        System.out.println(ok ? "登录成功！" : "用户名或密码错误！");
        ConsoleUtil.pause();
    }

    private static void listUsers() {
        System.out.println("\n--- 用户列表 ---");
        for (User u : service.listUsers()) {
            System.out.printf("%s | %s | %s%n", u.getName(), u.getType(), u.getPhone());
        }
        ConsoleUtil.pause();
    }

    private static void listMovies() {
        System.out.println("\n--- 影片列表 ---");
        for (Movie m : service.listMovies()) {
            System.out.printf("%s | %s | %d分钟 | %.1f分%n",
                    m.getName(), m.getDirector(), m.getDuration(), m.getScore());
        }
        ConsoleUtil.pause();
    }

    private static void listHalls() {
        System.out.println("\n--- 影厅列表 ---");
        for (Hall h : service.listHalls()) {
            System.out.printf("%s | %d排%d列 | 座位数%d%n",
                    h.getName(), h.getRows(), h.getCols(), h.seatCount());
        }
        ConsoleUtil.pause();
    }

    private static void listSessions() {
        System.out.println("\n--- 场次列表 ---");
        for (Session s : service.listSessions()) {
            System.out.printf("%s | %s | %s | ￥%.2f%n",
                    s.getId(), s.getMovieId(), s.getStartTime(), s.getPrice());
        }
        ConsoleUtil.pause();
    }
}